//
//  DepositSuccessViewController.m
//  NiuBanJin
//
//  Created by zf on 15/10/19.
//  Copyright © 2015年 zzjr. All rights reserved.
//

#import "DepositSuccessViewController.h"
#import "MyAccountViewController.h"
#import "WalletViewController.h"
@interface DepositSuccessViewController ()

@end

@implementation DepositSuccessViewController

#pragma mark - life cycle

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    [self pageSettingsAndSubviewsCreation]; //最新版，不用和server做交互
}

#pragma mark - SubviewsCreationAndPageSettings

- (void) pageSettingsAndSubviewsCreation {
    
    self.navigationItem.title = @"存入成功";
    
    self.view.backgroundColor = BASECOLOR;
    
    // 父view显示白色区域
    
    UIView *view_white = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, MULTIPLYHEIGHT(200))];
    view_white.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view_white];
    
    UIImageView *imageView_smile = [[UIImageView alloc]initWithFrame:CGRectMake(MULTIPLYWIDTH(120), MULTIPLYHEIGHT(30), MULTIPLYWIDTH(30), MULTIPLYHEIGHT(30))];
    imageView_smile.image = [UIImage imageNamed:@"smile.png"];
    [self.view addSubview:imageView_smile];
    
    UILabel *label_success = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(imageView_smile.frame) + MULTIPLYWIDTH(10), MULTIPLYHEIGHT(33), MULTIPLYWIDTH(100), MULTIPLYWIDTH(25))];
    label_success.text = @"存入成功";
    label_success.adjustsFontSizeToFitWidth = YES;
    label_success.font = [UIFont systemFontOfSize:25];
    label_success.textColor = [UsefulUtil colorWithHexString:@"#FF4747"];
    
    [self.view addSubview:label_success];
    
    
    UILabel *label_save = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(imageView_smile.frame) + MULTIPLYHEIGHT(25), SCREEN_WIDTH, MULTIPLYHEIGHT(15))];
    [label_save setTextAlignment:NSTextAlignmentCenter];
    
    NSString *text = [NSString stringWithFormat:@"成功存入: %@元",self.str_amount];  //显示余额
    label_save.adjustsFontSizeToFitWidth = YES;
    label_save.textColor = [UsefulUtil colorWithHexString:@"#434343"];
    
    NSMutableAttributedString *attributedStr_balance = [[NSMutableAttributedString alloc]initWithString:text];
    
    [attributedStr_balance addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(text.length - self.str_amount.length-1, self.str_amount.length)];
    label_save.attributedText = attributedStr_balance;
    
    [self.view addSubview:label_save];
    
    UILabel *label_exceptIncome = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(label_save.frame) + MULTIPLYHEIGHT(25/2.0), SCREEN_WIDTH, MULTIPLYHEIGHT(15))];
    [label_exceptIncome setTextAlignment:NSTextAlignmentCenter];
     label_exceptIncome.textColor = [UsefulUtil colorWithHexString:@"#434343"];
    
    CGFloat profit  = [self.str_amount floatValue] * [[UsefulUtil userRealRate] floatValue]/36500 ;
    
    NSString *str_dayProfit = [NSString stringWithFormat:@"%.2f",profit];
    
    NSString *str_exceptIncomeText = [NSString stringWithFormat:@"每日预期收益增加: %@元" , str_dayProfit];
   
    NSMutableAttributedString *attributedStr_exceptIncome = [[NSMutableAttributedString alloc]initWithString:str_exceptIncomeText];
    
    [attributedStr_exceptIncome addAttribute:NSForegroundColorAttributeName value:[UsefulUtil colorWithHexString:@"#Fb4747"] range:NSMakeRange(str_exceptIncomeText.length - 1 - str_dayProfit.length, str_dayProfit.length )];
    
    label_exceptIncome.adjustsFontSizeToFitWidth = YES;
    label_exceptIncome.attributedText = attributedStr_exceptIncome;
    [self.view addSubview:label_exceptIncome];
    

    UIButton *button_Ticket = [UIButton buttonWithType:UIButtonTypeSystem];
    button_Ticket.frame = CGRectMake(MULTIPLYWIDTH(90), CGRectGetMaxY(label_exceptIncome.frame) + MULTIPLYHEIGHT(25), MULTIPLYWIDTH(200), MULTIPLYHEIGHT(30));
    
    [button_Ticket setTitle:@"立即使用加息卷提高利率" forState:UIControlStateNormal];
    button_Ticket.layer.masksToBounds = YES;
    button_Ticket.tintColor = [UsefulUtil colorWithHexString:@"#Fb4747"];
    button_Ticket.layer.cornerRadius = 15;
    button_Ticket.layer.borderWidth = 1.0;
    button_Ticket.layer.borderColor = [UsefulUtil colorWithHexString:@"#Fb4747"].CGColor;
    [button_Ticket addTarget:self action:@selector(TicketAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button_Ticket];
    
    UIButton *button_complete = [UIButton buttonWithType:UIButtonTypeSystem];
    
    button_complete.frame = CGRectMake(MULTIPLYWIDTH(15), CGRectGetMaxY(button_Ticket.frame) + MULTIPLYHEIGHT(52), SCREEN_WIDTH - MULTIPLYWIDTH(30), MULTIPLYHEIGHT(45));
    
    button_complete.backgroundColor = [UsefulUtil colorWithHexString:@"#Fb4747"];
    [button_complete setTitle:@"完成" forState:UIControlStateNormal];
    [button_complete.titleLabel setFont:[UIFont systemFontOfSize:17.0]];
    [button_complete setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button_complete addTarget:self action:@selector(completeAction) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:button_complete];
}

#pragma mark -completeAction

- (void)completeAction {
    
    [self.navigationController popToRootViewControllerAnimated:YES];
}

#pragma mark -TicketAction

- (void)TicketAction:(UIButton *)sender {

    [CURRENT_WINDOW.rootViewController.tabBarController setSelectedIndex:1];
}

#pragma mark - custom return back method

- (void) backToPreviousPage {
    
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
